package com.hzystudynote;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
/** @author ASUS tests 1 2 3 1 2 4 2 3 4 2 3 5 3 4 5 */
public class StudyComparator {
  public static void main(String[] args) {
    Integer[][] tests = new Integer[5][3];
    Scanner input = new Scanner(System.in);
    for (int i = 0; i < tests.length; i++) {
      for (int j = 0; j < tests[0].length; j++) {
        tests[i][j] = input.nextInt();
      }
    }
    print(tests);
    Arrays.sort(tests, ((a, b) -> b[2].equals(a[2]) ? b[1] - a[1] : b[2] - a[2]));
    print(tests);
    Arrays.sort(
        tests,
        new Comparator<>() {
          @Override
          public int compare(Integer[] integers, Integer[] t1) {
            if (integers[integers.length - 1].equals(t1[integers.length - 1])) {
              return integers[integers.length - 2] - t1[integers.length - 2];
            }
            return integers[integers.length - 1] - t1[integers.length - 1];
          }
        });
    print(tests);
  }

  private static void print(Integer[][] numbers) {
    for (Integer[] number : numbers) {
      for (Integer num : number) {
        System.out.printf("%d ", num);
      }
      System.out.print("\n");
    }
    System.out.print("\n");
  }
}
